package cn.xm.lingshi.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.xm.lingshi.pojo.User;
import cn.xm.lingshi.pojo.YongHu;
import cn.xm.lingshi.service.YonghuService;
import cn.xm.lingshi.service.impl.YongHuServiceImpl;

public class ModPwdServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	
	public void destroy() {
		super.destroy(); 
		
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");
		String newPassword=request.getParameter("newpwd1");
		YonghuService user=new YongHuServiceImpl();
		YongHu users=(YongHu)request.getSession().getAttribute("denglu");
		int recore= user.modpassword(users.getUserId(), newPassword);
		if(recore==1){
			out.println("<script>alert('修改成功');history.back();</script>");
		}else{
			out.println("<script>alert('修改失败');history.back();</script>");
		}
		out.flush();
		out.close();
	}

	
	public void init() throws ServletException {
		
	}

}
